#!/bin/bash

export CLUSTER_NAME="orbstack"

kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
  name: default-token
  annotations:
    kubernetes.io/service-account.name: default
type: kubernetes.io/service-account-token
EOF

# 等待令牌控制器使用令牌填充 secret:
while ! kubectl describe secret default-token | grep -E '^token' >/dev/null; do
  echo "waiting for token..." >&2
  sleep 1
done

# 获取令牌
TOKEN=$(kubectl get secret default-token -o jsonpath='{.data.token}' | base64 --decode)

echo $TOKEN
# eyJhbGciOiJSUzI1NiIsImtpZCI6ImJPSkl1ZUtoOUd6NDRhRWpqUUdhQ0RJWFJjWjBCejNQeV9DM3hMT1N0dk0ifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjRjY2U0NDU3LWE2ZDYtNGIwZi1hMzZkLWU5MDc5YjZhYTYyZSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.jbl0WIPtfzgBYkZI-5rvITWVr5HH9ITxAADEO1ei5S7tWBheEZPGr3gVQXD7i0V7C1WbCt_I-yj5qroBax8ahX-Bz92QLw96ZRnxxBefpi0zD_YfgmABYEstZQ_QrdqmecSRZ1JmSptm7A0FO5t3qNthW8szLVHwGVcfVj9jO6k65mavrcds6FiVEfYuiAIGkgNwnmi8ghcmBwMWfwl_I9UDLf2u_ZuQf12UWGWyJE4TjPWp6IpKHzIGup4dL_74J1VFFQEVHiZe1lJRMbvLP7eFbtAKDAnrUPE29ubnV21RPKvmEVRzN00IEyoGI16Yp77OkYzXLy5wmfTdCeq1Zg



